package darknet.application.chat.impl.net.message;

import darknet.core.impl.net.AbstractMessage;
import darknet.core.spec.net.MessageHeader;
import darknet.core.spec.net.Node;

/**
 * A join channel message.
 *
 * A node send this message to the channel owner to notify him he just joined
 * the channel.
 *
 * @author Yoyo
 */
public class JoinChannelMessage extends AbstractMessage {

    /** The channel name */
    private String channelName;

    /**
     * Initialise a new Close channel message.
     *
     * @param from	     The node hosting the channel.
     * @param to	     The destination node.
     */
    public JoinChannelMessage(MessageHeader header, Node from, Node to,
            String channelName) {

	super(header, from, to);

	if (channelName == null || channelName.length() == 0) {
	    throw new IllegalArgumentException("channelName is invalid");
	}
	this.channelName = channelName;
    }

    public String getChannelName() {
	return channelName;
    }

    @Override
    public String toString() {

        StringBuilder builder = new StringBuilder("JoinChannelMessage[");
        builder.append("super=");
        builder.append(super.toString());
        builder.append(", ");
        builder.append("channelName=");
        builder.append(channelName);
        builder.append("]");
        return builder.toString();
    }
}
